<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/contract.class.php");
	
	$contract = new Contract(); 	
	$company = $contract->companyList();
	$employed = $contract->employedListSearch();
	$eps = $contract->epsList();
	$arp = $contract->arpList();
	$afp = $contract->afpList();
	$asesor = $contract->asesorList();
	$parafiscal = $contract->parafiscalList();
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
			
	if(isset($_POST['addContract']) && $_POST['addContract'] == 1){
		$action = $_POST["action"];
		$data->hdvc_code = 1;
		$data->hdv_code = trim(mysql_real_escape_string($_POST['hdv_code']));
		$data->cont_type = trim(mysql_real_escape_string($_POST['cont_type']));
		$data->cont_value = trim(mysql_real_escape_string($_POST['cont_value']));
		$data->cont_sal_periodo = trim(mysql_real_escape_string($_POST['cont_sal_periodo']));
		$data->cont_sal_value = trim(mysql_real_escape_string($_POST['cont_sal_value']));
		$data->cont_cargo = trim(mysql_real_escape_string($_POST['cont_cargo']));
		$data->cont_day_in = cambiarFormatoFecha($_POST['cont_day_in'],2);
		$data->cont_day_out = cambiarFormatoFecha($_POST['cont_day_out'],2);
		if (($_POST['cont_funeral']) == ''){
		$data->cont_funeral = 0;
		}
		else {
		$data->cont_funeral = trim(mysql_real_escape_string($_POST['cont_funeral']));
		}
		if (($_POST['cont_admin']) == ''){
		$data->cont_admin = 0;
		}
		else {
		$data->cont_admin = trim(mysql_real_escape_string($_POST['cont_admin']));
		}
		if (($_POST['cont_aporte_mutual']) == ''){
		$data->cont_aporte_mutual = 0;
		}
		else {
		$data->cont_aporte_mutual = trim(mysql_real_escape_string($_POST['cont_aporte_mutual']));
		}
		$data->eps_code = trim(mysql_real_escape_string($_POST['eps_code']));
		$data->arp_code = trim(mysql_real_escape_string($_POST['arp_code']));
		$data->afp_code = trim(mysql_real_escape_string($_POST['afp_code']));
		
		$data->cont_name_poliza = trim(mysql_real_escape_string($_POST['cont_name_poliza']));
		if (($_POST['cont_value_poliza']) == ''){
		$data->cont_value_poliza = 0;
		}
		else {
		$data->cont_value_poliza = trim(mysql_real_escape_string($_POST['cont_value_poliza']));
		}
		$data->cont_name_seguro_vida = trim(mysql_real_escape_string($_POST['cont_name_seguro_vida']));
		if (($_POST['cont_value_seguro_vida']) == ''){
		$data->cont_value_seguro_vida = 0;
		}
		else {
		$data->cont_value_seguro_vida = trim(mysql_real_escape_string($_POST['cont_value_seguro_vida']));
		}
		$data->cont_name_otros = trim(mysql_real_escape_string($_POST['cont_name_otros']));
		if (($_POST['cont_value_otros']) == ''){
		$data->cont_value_otros = 0;
		}
		else {
		$data->cont_value_otros = trim(mysql_real_escape_string($_POST['cont_value_otros']));
		}
		$data->hdv_email  = trim(mysql_real_escape_string($_POST['hdv_email']));
		$data->ase_code = trim(mysql_real_escape_string($_POST['ase_code']));
		$data->para_code = trim(mysql_real_escape_string($_POST['para_code']));
		$data->cont_description = trim(mysql_real_escape_string($_POST['cont_description']));


		if ( $data->hdv_code = $contract->addContract($data) ){
		
				if ( ! $contract->updateEmployedContratado($data) ){
					$msg_alert = true;
			}
			
			if ( $action == 1 )
				$msg_alert = true;
				$_SESSION["msg_cool"] .= 'El contrato fue adicionado satisfactoriamente!!.<br />';				
				echo "<script> window.location.href='listContract.php?show_msg=3'</script>";
				
		}
		else{
			$msg_info = true;
			$_SESSION["msg_cool"] .= 'No pudo ser adicionado el contrato!.<br />';
			echo "<script> window.location.href='listContract.php?show_msg=1'</script>";
		}


	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>